package cc.yaomm.service.basic.mapper.user.po;

import cc.yaomm.common.basic.lang.po.BaseParamPO;
import cc.yaomm.common.biz.enums.OwnerTypeEnum;
import cc.yaomm.service.basic.entity.user.Roles;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Objects;

/**
 * Created by XQL on 2021/6/28.
 */
@Data
public class RoleParamPO extends BaseParamPO {

    /**
     * 所属类型 1-业务系统 2-商家 3-集团账号
     */
    private OwnerTypeEnum ownerType;

    /**
     * 所属者ID
     */
    private Long ownerId;

    /**
     * 关键字
     */
    private String keyword;

    @Override
    public LambdaQueryWrapper<Roles> getWrapper() {
        LambdaQueryWrapper<Roles> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Objects.nonNull(this.ownerType), Roles::getOwnerType, this.ownerType);
        wrapper.eq(Objects.nonNull(this.ownerId), Roles::getOwnerId, this.ownerId);
        wrapper.and(StringUtils.hasText(keyword), wrap ->
                wrap.like(Roles::getName, keyword)
                        .or()
                        .like(Roles::getNote, keyword)
        );
        return wrapper;
    }
}

